package com.paul.sys.service.impl;

import com.paul.sys.mapper.PtstaffMapper;
import com.paul.sys.model.Ptstaff;
import com.paul.sys.service.PtstaffService;
import com.paul.sys.tools.CommPageBean;
import com.paul.sys.tools.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
public class PtstaffServiceImpl implements PtstaffService {

    @Autowired
    private PtstaffMapper ptstaffMapper;


    @Override
    public PageData<Ptstaff> listByPage(Map<String, String> param) {

        PageData<Ptstaff> pageData = new PageData<Ptstaff>();
        CommPageBean pageBean = CommPageBean.getPageBeanByParam(param);
        List<Ptstaff> list = ptstaffMapper.listByPage(param, pageBean);
        pageData.setPageBean(pageBean);
        pageData.setListData(list);

        return pageData;
    }

    @Override
    public PageData<Map> listRoleByUserByPage(Map user, Map<String, String> param) {
        PageData<Map> pageData = new PageData<Map>();
        CommPageBean pageBean = CommPageBean.getPageBeanByParam(param);
        List<Map> list = ptstaffMapper.listRoleByUserByPage(user, pageBean);
        pageData.setPageBean(pageBean);
        pageData.setListData(list);
        return pageData;
    }
//    @Cacheable(value = "ptstaff")
    @Override
    public Ptstaff selectByPrimaryKey(String unid) {
        return ptstaffMapper.selectByPrimaryKey(unid);
    }

    public int updateByPrimaryKey(Ptstaff record) {
        return ptstaffMapper.updateByPrimaryKey(record);
    }

    @Override
    public int updatePwd(Ptstaff record) {
        return ptstaffMapper.updatePwd(record);
    }

    ;

    @Override
    public int deleteByPrimaryKey(String unid) {
        return ptstaffMapper.deleteByPrimaryKey(unid);
    }

    ;

    @Override
    public int insertSelective(Ptstaff record) {

        int n=ptstaffMapper.insertSelective(record);
        ptstaffMapper.insertSelective(record);
//        n=0;
//        int a=10/n;
        return n;
    }

    ;

    @Override
    public List<Ptstaff> listAll(Map<String, String> param) {
        ptstaffMapper.selectByPrimaryKey("123");
        return ptstaffMapper.listAll(param);
    }

    @Override
    public int deleteByUnids(String[] unids) {
        return ptstaffMapper.deleteByUnids(unids);
    }

    @Override
    public int linkRole(Map<String, Object> param) {
        int n = 0;
        List list = ptstaffMapper.selectRoleLink(param);
        if (list.size() == 1) {
            n = ptstaffMapper.updateRoleLinkEnable(param);
        } else {
            n = ptstaffMapper.insertRoleLink(param);
        }
        return n;
    }

    @Override
    public int unlinkRole(Map<String, Object> param) {
        int n = 0;
        List list = ptstaffMapper.selectRoleLink(param);
        if (list.size() == 1) {
            n = ptstaffMapper.updateRoleLinkEnable(param);
        } else {
            n = 0;
        }
        return n;
    }

    @Override
    public Map<String, String> getUnid() {
        return ptstaffMapper.getUnid();
    }

    ;

    @Override
    public Ptstaff selectByCodeAndPass(Map<String, String> param) {
        return ptstaffMapper.selectByCodeAndPass(param);
    }

    ;

}